/**
 * Main class
 *
 * @author Jose Luis Quintana <joseluis@lbn.pe>
 **/

var Main = new Class({
    Implements: [Events, Options],
    options: {
        
    },
    
    header: $('header'),
    container: $('container'),
    footer: $('footer'),
    panel_left: null,
    
    initialize: function(options){
        this.setOptions(options);
        this.defaults();
    },
    reset: function(){
        $(document.body).setStyle('overflow', 'auto');
    },
    getSizeContainer: function(){
        return {
            'x': window.getSize().x,
            'y': window.getSize().y - (this.header.getSize().y + this.footer.getSize().y)
        }
    },
    panelLeft: function(){
        if ($('panel_left')) {
            var container,
            panel = $('panel_left'),
            handle = $('panel_handle');
            
            this.panel_left = panel;
            
            window.addEvent('resize', function(){
                container = this.getSizeContainer();
                panel.setStyle('height', container.y);                
                handle.setStyles({
                    'margin-left': panel.getStyle('width').toInt() - (handle.getStyle('height').toInt() / 2),
                    'margin-top': (container.y - handle.getStyle('height').toInt()) / 2
                });
            }.bind(this)).fireEvent('resize');
            
            // Handle
            handle.addEvent('click', function(){
                if (this.container.hasClass('close')) {
                    this.container.removeClass('close');
                    handle.set('html', '&laquo;');
                } else {
                    this.container.addClass('close');
                    handle.set('html', '&raquo;');
                }
                
                window.fireEvent('resize');
            }.bind(this));
            handle.setStyle('display', 'inline');
        }
    },
    checkTransition: function(){
        var obj = document.createElement('div'),
        props = ['perspectiveProperty', 'WebkitPerspective', 'MozPerspective', 'OPerspective', 'msPerspective'];
        
        for (var i in props) {
            if ( obj.style[props[i]] !== undefined ) {
                this.prefix = props[i].replace('Perspective','').toLowerCase();
                return true;
            }
        }
        
        return false;
    },
    defaults: function(){
        this.setMenu();
    },
    setMenu: function() {
        if (this.header) {
            var items = this.header.getElements('.main-submenu > li');
            items.each(function(e){
                e.addEvent('mouseover', function(){
                    items.removeClass('selected');
                    e.addClass('selected');
                });
            }.bind(this));
        }
    }
});